package com.webapp.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Jcopy
{
  public static void CopyFile(String source, String targetDir)
  {
    File in = new File(source);
    File outDir = new File(targetDir);
    FileInputStream fis = null;
    FileOutputStream fos = null;
    if (!(outDir.exists()))
      outDir.mkdirs();
    try
    {
      fis = new FileInputStream(in);
      fos = new FileOutputStream(targetDir + File.separator + in.getName());
      byte[] buf = new byte[1024];
      int i = 0;
      while ((i = fis.read(buf)) != -1) {
        fos.write(buf, 0, i);
      }
      fis.close();
      fos.close();
    }
    catch (FileNotFoundException e) {
      e.printStackTrace();
    }
    catch (IOException e) {
      e.printStackTrace();
    }
  }

  public static void main(String[] args)
  {
    CopyFile("c:\\oracle10g.pdf", "c:\\temp");
  }
}